package net.weitalk.asm;

import java.io.IOException;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;

public class Premain {
    public static void premain(String agentArgs, Instrumentation inst) {
        inst.addTransformer(new ClassFileTransformer() {
            @Override
            public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
                System.out.println(className);
                if (className.equals("java/lang/Integer")) {
                    System.out.println("transformed.");
                    CustomClassWriter cw = new CustomClassWriter(classfileBuffer);
                    return cw.addField();
                }
                return classfileBuffer;
            }
        });
    }
}
